var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/services/dept.ts
var dept_exports = {};
__export(dept_exports, {
  getDeptDetail: () => getDeptDetail,
  getDeptInitialTree: () => getDeptInitialTree,
  getDeptInitialTreeAuthed: () => getDeptInitialTreeAuthed,
  queryChildDeptTreeNodes: () => queryChildDeptTreeNodes,
  searchByName: () => searchByName,
  searchByNameAuthed: () => searchByNameAuthed
});
module.exports = __toCommonJS(dept_exports);
var import_umi = require("umi");
var import_dept = require("../utils/dept");
async function getDeptInitialTree(data, isSubApp) {
  return (0, import_umi.request)(`/dept/tree/new`, {
    method: "post",
    data,
    useCache: true,
    prefix: (0, import_dept.getPrefix)(isSubApp),
    headers: isSubApp ? { "User-App-Code": data.appCode } : void 0
  });
}
async function getDeptInitialTreeAuthed(data, isSubApp) {
  return (0, import_umi.request)(`/dept/data/perm/tree`, {
    method: "post",
    data,
    useCache: true,
    prefix: (0, import_dept.getPrefix)(isSubApp),
    headers: isSubApp ? { "User-App-Code": data.appCode } : void 0
  });
}
async function queryChildDeptTreeNodes(data, isSubApp) {
  var _a;
  const res = await (0, import_umi.request)(`/dept/son/list`, {
    method: "post",
    data: {
      ...data,
      pageNo: 1,
      pageSize: 1e3
    },
    useCache: true,
    prefix: (0, import_dept.getPrefix)(isSubApp),
    headers: isSubApp ? { "User-App-Code": data.appCode } : void 0
  });
  if ((res == null ? void 0 : res.success) && ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.list)) {
    return {
      ...res,
      data: {
        ...res.data,
        list: res.data.list.map(import_dept.convertDept2DeptTreeNode)
      }
    };
  }
  return {
    ...res,
    data: null
  };
}
async function getDeptDetail(data, options) {
  const { isSubApp = false, customDetailRequestUrl } = options || {};
  let url = void 0;
  if (isSubApp) {
    url = `/dept/detail`;
  } else {
    if (!customDetailRequestUrl) {
      throw new Error("请检查请求是否配置正确");
    }
    url = customDetailRequestUrl;
  }
  const res = await (0, import_umi.request)(url, {
    method: "post",
    data,
    useCache: true,
    prefix: (0, import_dept.getPrefix)(isSubApp),
    headers: isSubApp ? { "User-App-Code": data.appCode } : void 0
  });
  if ((res == null ? void 0 : res.success) && res.data) {
    return {
      ...res,
      data: (0, import_dept.convertDept2DeptTreeNode)(res.data)
    };
  }
  return res;
}
async function searchByName(data, isSubApp) {
  const res = await (0, import_umi.request)(`/dept/tree/by/name`, {
    method: "post",
    data,
    prefix: (0, import_dept.getPrefix)(isSubApp),
    headers: isSubApp ? { "User-App-Code": data.appCode } : void 0
  });
  if ((res == null ? void 0 : res.success) && (res == null ? void 0 : res.data)) {
    const { data: data2 } = res;
    const travser = (nodes) => {
      nodes.forEach((node) => {
        var _a;
        if ((_a = node.children) == null ? void 0 : _a.length) {
          travser(node.children);
        } else {
          node.isLeaf = true;
        }
      });
    };
    travser(data2);
    return {
      ...res,
      data: data2
    };
  }
  return res;
}
async function searchByNameAuthed(data, isSubApp) {
  const res = await (0, import_umi.request)(
    `/dept/tree/by/name/with/perm`,
    {
      method: "post",
      data,
      prefix: (0, import_dept.getPrefix)(isSubApp),
      headers: isSubApp ? { "User-App-Code": data.appCode } : void 0
    }
  );
  if ((res == null ? void 0 : res.success) && (res == null ? void 0 : res.data)) {
    const { data: data2 } = res;
    const travser = (nodes) => {
      nodes.forEach((node) => {
        var _a;
        if ((_a = node.children) == null ? void 0 : _a.length) {
          travser(node.children);
        } else {
          node.isLeaf = true;
        }
      });
    };
    travser(data2);
    return {
      ...res,
      data: data2
    };
  }
  return res;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getDeptDetail,
  getDeptInitialTree,
  getDeptInitialTreeAuthed,
  queryChildDeptTreeNodes,
  searchByName,
  searchByNameAuthed
});
